import json

def get_stored_username():
    """如果存储了用户名，就获取它"""
    filename = "username.json"
    try:
        with open(filename) as file_object:
            username = json.load(file_object)
            return username
    except FileNotFoundError:
        return None


def get_new_username():
    """提示用户输入用户名，并将其存储到文件中"""
    username = input("请输入你的用户名：")
    filename = "username.json"
    with open(filename, 'w') as file_object:
        json.dump(username, file_object)
    return username


def greet_user():
    """问候用户，并根据情况处理用户名相关事宜"""
    username = get_stored_username()
    if username:
        current_user = input(f"当前显示欢迎的用户是 {username}，这是你吗？(y/n) ")
        if current_user.lower() == 'y':
            print(f"欢迎回来，{username}!")
        else:
            username = get_new_username()
            print(f"欢迎你，{username}! 已为你更新用户名信息。")
    else:
        username = get_new_username()
        print(f"欢迎你，{username}!")


greet_user()